package model;

/**
 * The Brewery class contains information and methods for the Brewery fields.
 */

public class Brewery extends Ownable 
{
	final int FACTOR = 100;  
	private int dicesSum, numOfFieldTypeOwned;
	
	/**
	 * Constructor
	 * @param number: Field number
	 * @param name: Field name
	 * @param description: Field description
	 * @param price: Field price
	 */
	public Brewery(int number, String name, String description, int price) 
	{
		super(number, name, description, price);
	}
	
	/**
	 * Calculates the rent of a brewery, which depends on 100 times the dicesum
	 * times the number of brewerys the owner owns
	 */
	@Override
	public int rent() 
	{
		return FACTOR*dicesSum*numOfFieldTypeOwned;
	}
	
	/**
	 * Decides whether or not the player, who landed on the brewery field should pay rent
	 */
	@Override
	public boolean landOnField(Player player, int dicesSum, int numOfFieldTypeOwned) 
	{
		
		
		if (owner != null)
		{
			if (owner == player || pawned)
				payment = 0;
			
			else
				payment = rent();
			
			if (!pawned)
			{
				if(player.getBalance()>= payment){
					this.dicesSum = dicesSum;
					this.numOfFieldTypeOwned = numOfFieldTypeOwned;
					player.withdraw(rent());
					owner.deposit(rent());
					return true;
				}			
			}
			return false;
		}
		return true;
	}

	/**
	 * toString method
	 */

	@Override
	public String toString() {
		return "Brewery [FACTOR=" + FACTOR + ", dicesSum=" + dicesSum
				+ ", numOfFieldTypeOwned=" + numOfFieldTypeOwned + "]";
	}

	/**
	 * Returns the price of the brewery to calculate the valueOfAssets
	 */
	@Override
	public int valueOfAssets() 
	{
		return price;
	}

	/**
	 * Calculates number of houses on the brewery. Always returns 0.
	 */
	@Override
	public int numOfHouses() {
		return 0;
	}

	/**
	 * Calculates number of hotels on the brewery. Always returns 0.
	 */
	@Override
	public int numOfHotels() {
		return 0;
	}

	/**
	 * Returns a boolean for whether or not the brewery is pawned.
	 */
	@Override
	public boolean isPawned() 
	{
		return pawned;
	}
}
